import rest_framework.filters
from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.views import APIView

from home.models import Nav,Banner
from home.ser import NavSer, BannerSer

from django.core.cache import cache
# Create your views here.
class TopNav(APIView):
    def get(self,response):
        key='toplist'
        navlist=cache.get(key)
        if navlist:
            return Response({"code":200,"data":navlist})
        navs=Nav.objects.filter(isdel=False,position=1).order_by("sort")
        ser=NavSer(navs,many=True)
        cache.set(key,ser.data,60*60*24)
        return Response({"code":200,"data":ser.data})
class FootNav(APIView):
    def get(self,response):
        navs=Nav.objects.filter(isdel=False,position=0).order_by("sort")
        ser=NavSer(navs,many=True)
        return Response({"code":200,"data":ser.data})
class Banners(APIView):
    def get(self,response):
        navs=Banner.objects.filter(isdel=False).order_by("sort")
        ser=BannerSer(navs,many=True)
        return Response({"code":200,"data":ser.data})